<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>

		<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/1.7.8/axios.min.js" referrerpolicy="no-referrer">
		</script>
		<style>
			html,
			body {
				width: 100vw;
				margin: 0;
				padding: 0;
				box-sizing: border-box;
			}

			input,
			button {
				display: inline-block;
				width: 100%;
				height: 100px;

				font-size: 50px;
			}
		</style>
	</head>
	<body>
		<div>
			<input type="text" value="O24121100109032555335" />
			<button onclick="submit()">提交</button>
		</div>
		<script type="text/javascript">
			var input = document.getElementsByTagName('input')[0]

			function submit() {
				const formData = new FormData()
				formData.append('orderSn', input.value)
				axios.post("", formData).then(function(res) {
					let resdata = res.data.data
					if (typeof WeixinJSBridge == "undefined") {
						if (document.addEventListener) {
							document.addEventListener('WeixinJSBridgeReady', function() {
								goPay(resdata);
							}, false);
						} else if (document.attachEvent) {
							document.attachEvent('WeixinJSBridgeReady', function() {
								goPay(resdata);
							});
							document.attachEvent('onWeixinJSBridgeReady', function() {
								goPay(resdata);
							});
						}
					} else {
						goPay(resdata);
					}
				})
			}


			function goPay(data) {
				let resData = {
					"appId": data.appId,
					"timeStamp": data.timestamp,
					"nonceStr": data.nonceStr,
					"package": data.packageVal,
					"signType": data.signType,
					"paySign": data.paySign
				}

				WeixinJSBridge.invoke(
					'getBrandWCPayRequest', resData,
					res => {
						if (res.err_msg == "get_brand_wcpay_request:ok") {
							// 使用以上方式判断前端返回,微信团队郑重提示：
							//res.err_msg将在用户支付成功后返回ok，但并不保证它绝对可靠。
						}
						console.log("返回内容：" + res)
					});
			}
		</script>
	</body>
</html>